package com.wugh.fast.demo.service.impl;

import com.wugh.fast.demo.anno.SpelAnno;
import com.wugh.fast.demo.entity.Entity1;
import com.wugh.fast.demo.service.CacheService;
import com.wugh.fast.module.cache.anno.CacheTtl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 说明:
 *
 * @author wugh
 * @date 2019-07-24 16:30
 */
@CacheTtl(ttl = "100s")
@Service
public class CacheServiceImpl implements CacheService {
    @Override
    @CacheTtl("100s")
    @Cacheable(value = CacheService.CACHE_KEY_PREFIX, key = "#keyPart")
    @SpelAnno("#p0")
    public Entity1 get(String keyPart) {
        return new Entity1().setA(keyPart).setB(keyPart.length()).setC(new Date());
    }

    @Override
    public List<Entity1> get(List<String> keys) {
        return keys.stream().map(keyPart -> new Entity1().setA(keyPart).setB(keyPart.length()).setC(new Date())).collect(Collectors.toList());
    }

    @Override
    public Entity1 delete(String keyPart) {
        return null;
    }
}
